package org.wu.reggie.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.wu.reggie.dto.SetmealDto;
import org.wu.reggie.entity.Setmeal;

import java.util.List;

public interface SetMealMapper {

    @Select("select count(*) from setmeal where category_id = #{id}")
    long findSetMealByCategoryId(Long id);

    List<Setmeal> findByName(@Param("name") String name);

    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    @Insert("insert into setmeal values(null,#{categoryId},#{name},#{price},#{status},#{code},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser},0)")
    void save(SetmealDto setmealDto);

    // 根据id查询套餐
    @Select("select * from setmeal where id = #{id}")
    Setmeal findById(Long id);

    // 修改套餐基本信息
    void updateById(SetmealDto setmealDto);

    void updateSetmealStatus(Integer status,@Param("ids") List<Long> ids);

    @Select("select * from setmeal where category_id=#{categoryId} and status=#{status} ")
    List<Setmeal> findByCategoryId(@Param("categoryId") Long categoryId, @Param("status") Integer status);
}
